﻿using Microsoft.Extensions.Logging;
using ORS.OrderRobot.Domain;
using ORS.OrderRobot.IOC;

namespace ORS.OrderRobot.Service.Jobs
{
    /// <summary>
    /// 更新用户本地的登录信息
    /// </summary>
	public class UpdateLocalLoginTimeJob : IBackgroundJob<UpdateLocalLoginTimeArgs>, IScoped
    {
        private ILogger<UpdateLocalLoginTimeJob> _logger;
        private readonly IRepository<Account, int> _accountRepository;

        public UpdateLocalLoginTimeJob(
            ILogger<UpdateLocalLoginTimeJob> logger,
            IRepository<Account, int> accountRepository
        )
        {
            _logger = logger;
            _accountRepository = accountRepository;
        }
        public async Task ExecuteAsync(UpdateLocalLoginTimeArgs args)
        {
            var entity = await _accountRepository.GetAsync(x => x.Email == args.Email);
            if (entity!=null)
            {
                entity.LastLoginTime = args.CreateTime;
                await _accountRepository.UpdateAsync(entity);
            }
        }
    }
}

